package com.example.node;

import com.example.ProcessFlowContext;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.Map;

@LiteflowComponent(id = "confirmStrategy", name = "确认优惠策略节点")
@Component
@Slf4j
public class ConfirmStrategyNode extends NodeComponent {
    @Override
    public void process() throws Exception {
        ProcessFlowContext context = this.getContextBean(ProcessFlowContext.class);
        Map<String, BigDecimal> strategyMap = context.getStrategyMap();
        Map.Entry<String, BigDecimal> amount = strategyMap.entrySet().stream()
                .min(Map.Entry.comparingByValue())
                .orElse(null);
        log.info("优惠策略已确认：{}", amount);
        context.getOrder().setAmount(amount.getValue());
    }
}
